package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.OfferInfoAddDTO;
import org.jsola.hr.dto.OfferInfoUpdateDTO;
import org.jsola.hr.entity.OfferInfoDO;
import org.jsola.hr.query.OfferInfoQuery;
import org.jsola.hr.service.IOfferInfoService;
import org.jsola.hr.vo.OfferInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class OfferInfoTestHelper extends BaseTestHelper {
    
    @Autowired
    private IOfferInfoService offerInfoService;

    /**
     * 生成add测试数据
     * @return OfferInfoAddDTO
     */
    public OfferInfoAddDTO getOfferInfoAddDTO(){
        OfferInfoAddDTO offerInfoAddDTO = new OfferInfoAddDTO();
        offerInfoAddDTO.setName(getRandomValue("varchar",32));
        offerInfoAddDTO.setGender(SafeKit.getInteger(getRandomValue("tinyint",4)));
        offerInfoAddDTO.setPhone(getRandomValue("varchar",11));
        offerInfoAddDTO.setEmail(getRandomValue("varchar",255));
        offerInfoAddDTO.setEmailCopy(getRandomValue("varchar",255));
        offerInfoAddDTO.setEmailSecret(getRandomValue("varchar",255));
        offerInfoAddDTO.setExpiry(SafeKit.getInteger(getRandomValue("int",11)));
        offerInfoAddDTO.setExpiryDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        offerInfoAddDTO.setEntryDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        offerInfoAddDTO.setEmployType(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        offerInfoAddDTO.setInformalType(SafeKit.getInteger(getRandomValue("tinyint",4)));
        offerInfoAddDTO.setProbation(SafeKit.getInteger(getRandomValue("int",11)));
        offerInfoAddDTO.setRegularDate((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        offerInfoAddDTO.setDepId(getRandomValue("varchar",32));
        offerInfoAddDTO.setPositionId(getRandomValue("varchar",32));
        offerInfoAddDTO.setCompany(getRandomValue("varchar",255));
        offerInfoAddDTO.setRank(getRandomValue("varchar",255));
        offerInfoAddDTO.setHrbp(getRandomValue("varchar",255));
        offerInfoAddDTO.setCompanyId(getRandomValue("varchar",32));
        offerInfoAddDTO.setSupervisor(getRandomValue("varchar",255));
        offerInfoAddDTO.setManagerForm(SafeKit.getInteger(getRandomValue("tinyint",4)));
        offerInfoAddDTO.setWorkCityId(getRandomValue("varchar",32));
        offerInfoAddDTO.setWorkCity(getRandomValue("varchar",255));
        offerInfoAddDTO.setEntryAddr(getRandomValue("varchar",255));
        offerInfoAddDTO.setEntryContact(getRandomValue("varchar",255));
        offerInfoAddDTO.setEntryPhone(getRandomValue("varchar",255));
        offerInfoAddDTO.setCompanyAddr(getRandomValue("varchar",255));
        offerInfoAddDTO.setSalaryMode(SafeKit.getInteger(getRandomValue("tinyint",4)));
        offerInfoAddDTO.setSalaryBasic(SafeKit.getInteger(getRandomValue("int",11)));
        offerInfoAddDTO.setSalaryRemark(getRandomValue("varchar",255));
        offerInfoAddDTO.setAttachment(getRandomValue("varchar",32));
        offerInfoAddDTO.setStatus(SafeKit.getInteger(getRandomValue("tinyint",4)));
        return offerInfoAddDTO;
    }


    /**
     * 生成update测试数据
     * @return OfferInfoUpdateDTO
     */
    public OfferInfoUpdateDTO getOfferInfoUpdateDTO(OfferInfoVO offerInfoVO){
        return offerInfoService.selectDOById(offerInfoVO.getId(), SITE_ID).to(OfferInfoUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return OfferInfoQuery
     */
    public OfferInfoQuery getOfferInfoQuery() {
        OfferInfoQuery offerInfoQuery = new OfferInfoQuery();
        List<OfferInfoDO> offerInfoDOList = offerInfoService.list(new OfferInfoDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(offerInfoDOList)) {
            OfferInfoDO offerInfoDO = offerInfoDOList.get(0);
            offerInfoQuery = offerInfoDO.to(OfferInfoQuery.class);
            if (offerInfoDO.getExpiryDate() != null) {
                offerInfoQuery.setExpiryDateStart(DateKit.getBeforeDay(offerInfoDO.getExpiryDate(),-1));
                offerInfoQuery.setExpiryDateEnd(DateKit.getBeforeDay(offerInfoDO.getExpiryDate(),1));
            }
            if (offerInfoDO.getEntryDate() != null) {
                offerInfoQuery.setEntryDateStart(DateKit.getBeforeDay(offerInfoDO.getEntryDate(),-1));
                offerInfoQuery.setEntryDateEnd(DateKit.getBeforeDay(offerInfoDO.getEntryDate(),1));
            }
            if (offerInfoDO.getRegularDate() != null) {
                offerInfoQuery.setRegularDateStart(DateKit.getBeforeDay(offerInfoDO.getRegularDate(),-1));
                offerInfoQuery.setRegularDateEnd(DateKit.getBeforeDay(offerInfoDO.getRegularDate(),1));
            }
            if (offerInfoDO.getSalaryBasic() != null) {
                offerInfoQuery.setSalaryBasicStart(SafeKit.getInteger(offerInfoDO.getSalaryBasic() - 1));
                offerInfoQuery.setSalaryBasicEnd(SafeKit.getInteger(offerInfoDO.getSalaryBasic() + 1));
            }
            if (offerInfoDO.getGmtCreate() != null) {
                offerInfoQuery.setGmtCreateStart(DateKit.getBeforeDay(offerInfoDO.getGmtCreate(),-1));
                offerInfoQuery.setGmtCreateEnd(DateKit.getBeforeDay(offerInfoDO.getGmtCreate(),1));
            }
            if (offerInfoDO.getGmtModified() != null) {
                offerInfoQuery.setGmtModifiedStart(DateKit.getBeforeDay(offerInfoDO.getGmtModified(),-1));
                offerInfoQuery.setGmtModifiedEnd(DateKit.getBeforeDay(offerInfoDO.getGmtModified(),1));
            }
        }
        return offerInfoQuery;
    }

    /**
     * 保存示例
     * @return OfferInfoVO
     */
    public OfferInfoVO saveOfferInfoExample(){
        OfferInfoAddDTO addDTO = this.getOfferInfoAddDTO();
        OfferInfoVO offerInfoVO = offerInfoService.save(addDTO,buildTokenUser());
        return offerInfoVO;
    }


}

